/**
 * TODO, pre_allocate list memory for performance
 *
 */

#ifndef _LOG_H_
#define _LOG_H_

#include "singleton.h"
#include "log_impl.h"
#include "log_defines.h"

#define LOG_FATAL
#define LOG_ERROR
#define LOG_WARN
#define LOG_INFO
#define LOG_DEBUG
#define LOG_TRACE

namespace trident
{

/**
 * @brief init log
 * @return int 0 successful, -1 failed
 */
static int initLog(const string& file_path_,
        const string& file_name_,
        log_level_e log_level_ = LOG_LEVEL_TRACE,
        unsigned long file_max_size_ = FILE_DEFAULT_MAX_SIZE,
        int log_fmt_ = LOG_FMT_DATE|LOG_FMT_MSECOND|LOG_FMT_LEVEL)
{
    return singleton_t<log_impl_t>::instance().init(file_path_, file_name_, log_level_, file_max_size_, log_fmt_);
}

#ifdef LOG_FATAL
    #define logFatal(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_FATAL, fmt_, ##__VA_ARGS__)
#else
    #define logFatal(fmt_, ...) 
#endif

#ifdef LOG_ERROR
    #define logError(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_ERROR, fmt_, ##__VA_ARGS__)
#else
    #define logError(fmt_, ...) 
#endif

#ifdef LOG_WARN
    #define logWarn(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_WARN, fmt_, ##__VA_ARGS__)
#else
    #define logWarn(fmt_, ...) 
#endif

#ifdef LOG_INFO
    #define logInfo(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_INFO, fmt_, ##__VA_ARGS__)
#else
    #define logInfo(fmt_, ...) 
#endif

#ifdef LOG_TRACE
    #define logTrace(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_TRACE, fmt_, ##__VA_ARGS__)
#else
    #define logTrace(fmt_, ...) 
#endif

#ifdef LOG_DEBUG
    #define logDebug(fmt_, ...) singleton_t<log_impl_t>::instance().doLog(LOG_LEVEL_DEBUG, fmt_, ##__VA_ARGS__)
#else
    #define logDebug(fmt_, ...) 
#endif

} // namespace trident

#endif //_LOG_H_
